package com.frank.eduservice.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.frank.eduservice.entity.EduTeacher;
import com.frank.eduservice.mapper.EduTeacherMapper;
import com.frank.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.frank.eduservice.vo.EduTeacherQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * <p>
 * 讲师 服务实现类
 * </p>
 *
 * @author Frank
 * @since 2021-11-12
 */
@Service
public class EduTeacherServiceImpl extends ServiceImpl<EduTeacherMapper, EduTeacher> implements EduTeacherService {
    @Autowired
    private EduTeacherMapper eduTeacherMapper;

    @Override
    public void conditionPage(Page<EduTeacher> page, EduTeacherQueryVo teacherQueryVo) {
        QueryWrapper<EduTeacher> queryWrapper = new QueryWrapper<>();
        if (StrUtil.isNotBlank(teacherQueryVo.getName())) {
            queryWrapper.like("name", teacherQueryVo.getName());
        }
        if (!Objects.isNull(teacherQueryVo.getLevel())) {
            queryWrapper.eq("level", teacherQueryVo.getLevel());
        }
        if (StrUtil.isNotBlank(teacherQueryVo.getBegin())) {
            queryWrapper.ge("gmt_create", teacherQueryVo.getBegin());
        }
        if (StrUtil.isNotBlank(teacherQueryVo.getEnd())) {
            queryWrapper.le("gmt_modified", teacherQueryVo.getEnd());
        }
        eduTeacherMapper.selectPage(page, queryWrapper);
    }
}
